﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.IO;

namespace Commander.Views
{
    /// <summary>
    /// Логика взаимодействия для SelectDisc.xaml
    /// </summary>
    public partial class SelectDisc : Window
    {
        private string patch;
        
        public SelectDisc()
        {
            InitializeComponent();
            patch = "null";
        }

        public string Patch
        {
            get
            {
                return patch;
            }
            set
            {
                patch = value;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DriveInfo[] allDrivers = DriveInfo.GetDrives();
            foreach (var drv in allDrivers)
            {
                listBox1.Items.Add(drv.Name);
            }
        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                string str = listBox1.SelectedItem.ToString();
                DriveInfo[] allDrivers = DriveInfo.GetDrives();
                foreach (var drv in allDrivers)
                {
                    if (drv.Name == str)
                    {
                        if (drv.IsReady)
                        {
                            patch = drv.Name;
                            this.Close();
                        }
                        else
                        {
                            label1.Content = "Диск " + drv.Name + " не готов, виберете другой диск";
                            listBox1.SelectedIndex = -1;
                        }
                    }
                }
            }
            catch(Exception a)
            {
                MessageBox.Show(a.ToString());
            }
            //MessageBox.Show(listBox1.SelectedItem.ToString());
        }
    }
}
